/**
 * 
 */
package cn.maszy.common;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.opensymphony.xwork2.ActionSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

/** 
 * @作者 Allen Shu 
 * @创建日期 2012-6-2 
 * @版本 V 1.0 
 */

public class BaseAction<T> extends ActionSupport implements
ServletResponseAware, ServletRequestAware, SessionAware {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected static final String OPERATION_DONE = "operationDone";
	protected static Log log = null;
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected Map<String, Object> session;
	private int statusCode = 200;
	private String message = null;
	private String forwardUrl = null;
	private String navTabId= null;
	private String callbackType= null;
	private String rel=null;
	
	protected int numPerPage ; // 每页显示多少条
	public int pageNumShown = 5;// 页标数字多少个
	protected int pageNum; // 当前页码 上一页加1
	protected Pager<T> pager;
	
	protected String orderField;
	protected String orderDirection;
	protected String lookup;
	protected String suggest;

	public String getSuggest() {
		return suggest;
	}
	public void setSuggest(String suggest) {
		this.suggest = suggest;
	}
	public String getLookup() {
		return lookup;
	}
	public void setLookup(String lookup) {
		this.lookup = lookup;
	}
	public String getOrderField() {
		return orderField;
	}
	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}
	public String getOrderDirection() {
		return orderDirection;
	}
	public void setOrderDirection(String orderDirection) {
		this.orderDirection = orderDirection;
	}
	public BaseAction() {
		super();
		log = LogFactory.getLog(this.getClass());
	}
	public int getStatusCode() {
		return statusCode;
	}

	public void setStatusCode(int statusCode){
		this.statusCode = statusCode;
	}
	
	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getForwardUrl() {
		return forwardUrl;
	}

	public void setForwardUrl(String forwardUrl) {
		this.forwardUrl = forwardUrl;
	}
	
	public String getRel() {
		return rel;
	}
	public void setRel(String rel) {
		this.rel = rel;
	}
	public String getNavTabId() {
		return navTabId;
	}
	public void setNavTabId(String navTabId) {
		this.navTabId = navTabId;
	}
	public String getCallbackType() {
		return callbackType;
	}
	public void setCallbackType(String callbackType) {
		this.callbackType = callbackType;
	}
	
	public int getNumPerPage() {
		return numPerPage;
	}
	public void setNumPerPage(int numPerPage) {
		this.numPerPage = numPerPage;
	}
	public int getPageNumShown() {
		return pageNumShown;
	}
	public void setPageNumShown(int pageNumShown) {
		this.pageNumShown = pageNumShown;
	}
	
	public int getPageNum() {
		return pageNum;
	}
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	
	public Pager<T> getPager() {
		return pager;
	}
	public void setPager(Pager<T> pager) {
		this.pager = pager;
	}
	protected void margeForwardUrl(String target, String replacement) {
		if (StringUtils.notEmpty(forwardUrl) && target != null
				&& replacement != null) {
			forwardUrl = forwardUrl.replace(target, replacement);
		}
	}

	private String ajaxForward(int statusCode) {
		this.statusCode = statusCode;
		return OPERATION_DONE;
	}
	
	/**
	 * @param message
	 * 				return message
	 * @param navTabId
	 * 				the tab id
	 * @param callbackType
	 * @param forwardUrl				
	 */
	protected String ajaxForwardSuccess(String message,String navTabId,String rel,String callbackType,String forwardUrl) {
		this.message = message;
		this.navTabId=navTabId;
		this.rel = rel;
		this.callbackType=callbackType;
		this.forwardUrl=forwardUrl;
		return ajaxForward(200);
	}
	protected String ajaxForwardError(String message) {
		this.message = message;
		return ajaxForward(300);
	}
	/* (non-Javadoc)
	 * @see org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
	 */
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session = session;
	}
	/* (non-Javadoc)
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
	 */
	public void setServletRequest(HttpServletRequest request) {
		// TODO Auto-generated method stub
		this.request = request;
	}
	/* (non-Javadoc)
	 * @see org.apache.struts2.interceptor.ServletResponseAware#setServletResponse(javax.servlet.http.HttpServletResponse)
	 */
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.response=response;
	}
}
